import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login.vue'
import home from '../components/home.vue'
import welcome from '../components/welcome.vue'
import users from '../components/users.vue'
import Rights from '../components/power/Rights'
import Cate from '../components/power/Cate'

import Roles from '../components/power/Roles.vue'
import Params from '../components/power/Params.vue'
import List from '../components/power/List.vue'
import add from '../components/power/add'
import order from '../components/power/order'
import reports from '../components/power/reports'
Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/login' },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/home',
    component: home,
    redirect: '/welcome',
    children: [
      { path: '/welcome', component: welcome },
      { path: '/users', component: users },
      { path: '/rights', component: Rights },
      { path: '/roles', component: Roles },
      { path: '/categories', component: Cate },
      { path: '/params', component: Params },
      { path:'/goods',component:List },
      {path: '/goods/add',component:add},
      {path:'/orders',component:order},
      {
        path:'/reports',component:reports
      }


    ]
  }

]

const router = new VueRouter({
  routes
})
router.beforeResolve((to, from, next) => {
  if (to.path === '/login') return next()
  const tokenStr = window.sessionStorage.getItem('token')
  if (!tokenStr) return next('/login')
  next()
})

export default router
